package otherPractice;

import java.util.Arrays;
import java.util.Random;

public class ShuffleDemo {

    public static void main(String[] args) {
        int[] initArr = {1,2,3,4,5,6,7,8,9};
        int[] backArr = Arrays.copyOf(initArr, initArr.length);

         shuffle(backArr);
//        for(int i=0; i<backArr.length; i++){
//            int index = (int)(Math.random()*backArr.length);
//            int temp = backArr[i];
//            backArr[i] = backArr[index];
//            backArr[index] = temp;
//        }


        System.out.println("initArr=" + Arrays.toString(initArr));
        System.out.println("backArr=" + Arrays.toString(backArr));

    }

    private static void shuffle(int[] arr){
        Random random = new Random();
        for(int i = arr.length-1; i>1; i--){
            int index = random.nextInt(i);
            int temp = arr[i];
            arr[i] = arr[index];
            arr[index] = temp;
        }

    }



}
